import Vue from 'vue'
//1.导入vuex
import Vuex from 'vuex'

import VuexPersistedstate from 'vuex-persistedstate'
//2.注册vuex
Vue.use(Vuex)
//3.实例化并导出vuex实例
export default new Vuex.Store({
  state: { //负责存储数据
    lovelist: [],
    searchBox: [],
    slist: [],
    lolist: [],
    save:[]
  },
  getters: { //负责定义计算方法(类似于组件中的计算属性)

  },
  mutations: { //负责定义同步方法( 可以直接修改state中的数据 )
    add(state, payload) {
      state.lovelist.push({ id: payload })
      state.lovelist=[]
        console.log(state.lovelist);
    },
    getId(state, payload) {
      var index = state.lovelist.find((item, index) => {
        return item.mtWmPoiId = payload.mtWmPoiId
      })
      if (index != -1) {
        state.lovelist.splice(index, 1)
        console.log(state.lovelist);
      }
    },
    addSear(state, payload) {
      state.searchBox.push({ name: payload })
      console.log(state.searchBox);
    },
    addList(state, payload) {
      state.slist.push(payload)
      console.log(state.slist);
    },
    addLolist(state, payload) {
      state.lolist.push(payload )
      console.log(state.lolist);
    },
    SaveIndex(state, payload) {
      state.save.push(payload)
      // state.save=[]
      console.log(state.save);
    }
  },
  actions: { //负责定义异步方法( 内部一般书写异步代码( 定时器,ajax ) 不可以直接修改state中的数据 )

  },
  modules: { //实现state的模块化管理

  },
  plugins: [VuexPersistedstate()] //配合其他插件管理state中的数据
})
